package com.xncoding.freemarker.base;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.xncoding.freemarker.utile.LocalUtil;
import lombok.Data;

import java.util.Date;

/**
 * idcoed:2025021116
 */
@Data
public class ErrorResponse {

    private int code;

    @JsonIgnore
    private int status;

    private String msg;

    private String path;

    private Date dateTime;

    private Object data = new Object();

    private Boolean success=false;

    public ErrorResponse() {
    }

    /**
     * 服务器未知错误（非业务类错误）
     * @param msg 错误信息
     * @param path 访问接口
     */
    public ErrorResponse(String msg,String path) {
        this(100000, 500, msg, path, null);
    }

    public ErrorResponse(BaseException ex, String path) {
        this(Integer.parseInt(ex.getError().getCode()), ex.getError().getStatus().value(), LocalUtil.getErrorMsg(ex)==null?ex.getError().getValue():LocalUtil.getErrorMsg(ex), path, ex.getData());
    }

    public ErrorResponse(int code, int status, String message, String path, Object data) {
        this.code = code;
        this.status = status;
        this.msg = message;
        this.path = path;
        this.dateTime = new Date();
        this.data=data;
    }
}
